<template>
  <!-- <h1>register</h1> -->
  <!-- 第一种方法 -->
  <!-- <router-link to="/login">已有账号，去登录</router-link> -->
  <!-- 第二种方法  :to="{path:'需要跳转页面的浏览器路径'}" -->
  <!-- <router-link :to="{path:'/login'}">已有账号，去登录</router-link> -->
  <!-- 第三种方法  :to="{name:'需要跳转页面的路由名称'}" -->
  <!-- <router-link :to="{name:'Login'}">已有账号，去登录</router-link> -->
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>注册</span>
    </div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="账号">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="register" style="margin-right: 30px"
          >立即注册</el-button
        >
        <router-link to="/login">已有账号，去登录</router-link>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: "admin",
        password: "123",
      },
    };
  },
  methods: {
    async register() {
      const res = await this.$api.register.users(this.form);
      console.log(res);
      if (res.code) {
       
        this.$message({
          message: "注册成功",
          type: "success",
        });
        this.$router.push("/login");
      } else {
        this.$message.error("注册失败");
      }
    },
  },
};
</script>

<style>
.el-card {
  width: 500px;
  margin: 100px auto;
}
</style>
